package com.zygh.lz.controller.pc;

import com.zygh.lz.entity.IllegalData;
import com.zygh.lz.entity.IllegalDept;
import com.zygh.lz.service.ProblemService;
import com.zygh.lz.service.RecordService;
import com.zygh.lz.service.SignService;
import com.zygh.lz.service.XareaService;
import com.zygh.lz.service.impl.GpsServiceImpl;
import com.zygh.lz.service.impl.IllegalDataService;
import com.zygh.lz.service.impl.IllegalService;
import com.zygh.lz.service.impl.InformationUserService;
import com.zygh.lz.stapprove.ResultUtil;
import com.zygh.lz.stapprove.SysPcLog;
import com.zygh.lz.vo.ResultBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.List;

@Slf4j
@Api(tags = "领导驾驶舱")
@RestController
@RequestMapping("/RecordController")
public class RecordController {

    @Resource
    private RecordService recordService;
    @Resource
    private IllegalDataService illegalDataService;
    @Resource
    private IllegalService illegalService;
    @Resource
    private SignService signService;
    @Resource
    private ProblemService problemService;
    @Resource
    private XareaService xareaService;
    @Resource
    private GpsServiceImpl gpsService;

    @Resource
    private InformationUserService informationUserService;


    @GetMapping("calculateVitality")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "staffId", value = "人员id 和大队ID必须传一个/同时传查个人", dataType = "Integer"),
            @ApiImplicitParam(name = "sectionId", value = "大队ID", dataType = "Integer"),
            @ApiImplicitParam(name = "startTime", value = "开始时间", dataType = "String", required = true),
            @ApiImplicitParam(name = "endTime", value = "结束时间", dataType = "String", required = true)

    })
    public ResultBean calculateVitality(Integer staffId, Integer sectionId, String startTime, String endTime) {

        return recordService.calculateVitality(staffId, sectionId, startTime, endTime);

    }

    @ApiOperation("查询签到人数及活跃度")
    @GetMapping("calculateVitalityPlus")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sectionId", value = "部门ID", dataType = "Integer"),
            @ApiImplicitParam(name = "startTime", value = "开始时间", dataType = "String", required = true),
            @ApiImplicitParam(name = "endTime", value = "结束时间", dataType = "String", required = true)
    })
    public ResultBean calculateVitalityPlus(Integer sectionId, String startTime, String endTime) {

        return recordService.calculateVitalityPlus(sectionId, startTime, endTime);

    }

    @ApiOperation("出勤街道统计")
    @GetMapping("gateStreet")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "staffId", value = "人员id", dataType = "Integer"),
            @ApiImplicitParam(name = "startTime", value = "开始时间", dataType = "String", required = true),
            @ApiImplicitParam(name = "endTime", value = "结束时间", dataType = "String", required = true)

    })
    public ResultBean gateStreet(Integer staffId, String startTime, String endTime) {
        return recordService.gateStreet(staffId, startTime, endTime);

    }


    @ApiOperation("违法数据插入，视频网调用接口")
    @GetMapping("insertIgnore")
    //@SysPcLog(module = "违法数据插入，视频网调用接口",operation = "违法数据插入，视频网调用接口")
    public int insertIgnore(IllegalData illegalData) {
        int i = illegalDataService.insertIgnoreNull(illegalData);
//        log.info("插入未发数据:{},影响行数{}", illegalData,i);
        return i;
    }

    @ApiOperation("违法数据查询本地最新一条数据，视频网调用接口")
    @GetMapping("findIllegalDataEnd")
    public IllegalData findIllegalDataEnd(String type, String battalion) {
        return illegalDataService.findIllegalDataEnd(type, battalion);
    }


    @ApiOperation("违法库里匹配的部门名称，视频网调用接口")
    @GetMapping("findAll")
    public List<IllegalDept> findAll() {
        return illegalDataService.findAll();
    }


    @ApiOperation("在线人数")
    @GetMapping("onlineNumber")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "部门id", dataType = "Integer"),

    })
    public ResultBean onlineNumber(Integer id) {
        return ResultUtil.setOK("success", signService.onlineNumber(id));
    }

    @ApiOperation("巡查总里程")
    @GetMapping("totalMileage")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "部门id", dataType = "Integer"),
    })
    public ResultBean totalMileage(Integer id) {
        return ResultUtil.setOK("success", signService.totalMileage(id));
    }


    @ApiOperation("信息报送")
    @GetMapping("reportInformation")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "登录账号id", dataType = "Integer", required = true),
    })
    public ResultBean reportInformation(Integer id) {
        return ResultUtil.setOK("success", problemService.reportInformation(id));
    }

    @ApiOperation("岗位·人员统计")
    @GetMapping("personnelStatistics")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "部门id", dataType = "Integer"),
    })
    public ResultBean personnelStatistics(Integer id) {
        return ResultUtil.setOK("success", xareaService.personnelStatistics(id));
    }

    @ApiOperation("当日数据统计，各种事件")
    @GetMapping("dataStatistics")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "部门id", dataType = "Integer"),
    })
    public ResultBean dataStatistics(Integer id) {
        return ResultUtil.setOK("success", illegalDataService.dataStatistics(id));

    }


    /**
     * ==================================个人档案模块=============================
     */

    @ApiOperation("勤务信息")
    @GetMapping("personalFile")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "人员id", dataType = "Integer", required = true),
    })
    public ResultBean personalFile(int id) {
        return ResultUtil.setOK("success", gpsService.findGpsStatistics(id, null, null));
    }

    @ApiOperation("执法信息")
    @GetMapping("findIllegalDataByCode")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "人员id", dataType = "Integer", required = true),
    })
    public ResultBean findIllegalDataByCode(int id) {
        return ResultUtil.setOK("success", illegalDataService.findIllegalDataByCode(id, null, null, null));
    }

    @ApiOperation("执法数据")
    @GetMapping("findIllegalInfoByCode")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "人员id", dataType = "Integer", required = true),
    })
    public ResultBean findIllegalInfoByCode(int id, String startTime, String endTime, Integer sectionId) {
        return ResultUtil.setOK("success", illegalDataService.findIllegalData(id, startTime, endTime, sectionId));
    }

    @ApiOperation("执法数据折线图")
    @GetMapping("findIllegalline")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "人员id", dataType = "Integer", required = true),
    })
    public ResultBean findIllegalline(int id, String startTime, String endTime) throws ParseException {
        return ResultUtil.setOK("success", illegalDataService.findIllegalline(id, startTime, endTime));
    }


    @ApiOperation("接处警排名")
    @GetMapping("findJieChuJingByCode")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "人员id", dataType = "Integer", required = true),
    })
    public ResultBean findJieChuJingByCode(int id, String startTime, String endTime) {
        return ResultUtil.setOK("success", recordService.findJieChuJingByCode(id, startTime, endTime));
    }


    @ApiOperation("执法数据詳情")
    @GetMapping("findIllegalDataByInfo")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "人员id", dataType = "Integer", required = true),
            @ApiImplicitParam(name = "startDate", value = "开始时间", dataType = "Integer", required = true),
            @ApiImplicitParam(name = "endDate", value = "结束时间", dataType = "Integer", required = true),
            @ApiImplicitParam(name = "type", value = "违法类型", dataType = "Integer"),
            @ApiImplicitParam(name = "current", value = "页码", dataType = "Integer", required = true),
            @ApiImplicitParam(name = "size", value = "每页数量", dataType = "Integer", required = true),
    })
    public ResultBean findIllegalDataByInfo(int id, String startDate, String endDate, String type,
                                            @RequestParam(name = "current", defaultValue = "1") Integer current,
                                            @RequestParam(name = "size", defaultValue = "10") Integer size) {
        return ResultUtil.setOK("success", illegalDataService.findIllegalDataByInfo(id, startDate, endDate, type, current, size));
    }

    @ApiOperation("违法代码类型")
    @GetMapping("illegalCode")
    public ResultBean illegalCode() {
        return ResultUtil.setOK("success", illegalService.illegalCode());
    }


    @ApiOperation("调度信息")
    @GetMapping("schedulingInformation")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "人员id", dataType = "Integer", required = true),
    })
    public ResultBean schedulingInformation(int id) {
        return ResultUtil.setOK("success", informationUserService.schedulingInformation(id));
    }

    @ApiOperation("上报问题")
    @GetMapping("reportedProblem")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "人员id", dataType = "Integer", required = true),
            @ApiImplicitParam(name = "startDate", value = "开始时间", dataType = "Integer", required = true),
            @ApiImplicitParam(name = "endDate", value = "结束时间", dataType = "Integer", required = true),
    })
    public ResultBean reportedProblem(int id, String startDate, String endDate,
                                      @RequestParam(name = "current", defaultValue = "1") Integer current,
                                      @RequestParam(name = "size", defaultValue = "10") Integer size) {
        return ResultUtil.setOK("success", problemService.reportedProblem(id, startDate, endDate, current, size));
    }

    @ApiOperation("调度指挥折线图")
    @GetMapping("schedulingLine")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "warningSignal", value = "警号", dataType = "String", required = true),
            @ApiImplicitParam(name = "startDate", value = "开始时间", dataType = "Integer", required = true),
            @ApiImplicitParam(name = "endDate", value = "结束时间", dataType = "Integer", required = true),
    })
    public ResultBean schedulingLine(String warningSignal, String startDate, String endDate) throws ParseException {

        return informationUserService.schedulingLine(warningSignal, startDate, endDate);
    }

    @ApiOperation("上报问题折线图")
    @GetMapping("reportedProblemLine")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "人员id", dataType = "Integer", required = true),
            @ApiImplicitParam(name = "startDate", value = "开始时间", dataType = "Integer", required = true),
            @ApiImplicitParam(name = "endDate", value = "结束时间", dataType = "Integer", required = true),
    })
    public ResultBean reportedProblemLine(int id, String startDate, String endDate) throws ParseException {
        return ResultUtil.setOK("success", problemService.reportedProblemLine(id, startDate, endDate));
    }


}
